<?php 
/**
 * 
 * @author HZ_02
 * 会员实体类  
 */
class MemberAction extends CommonAction{

	/**
	 * 会员列表
	 */
	public function index(){
		
		import('ORG.Util.Page');
		
		$keys   = $this->_param("keywords","trim","");
		
		if($keys){
			$map["username|realname"] = array('like','%'.$keys.'%');
		}
		
		
		$model  = D("MemberInfoView");
		$count  = $model->where($map)->count();
		$Page   = new Page($count,5);
		$show   = $Page->show();
		
		$list   = $model->where($map)->order('id asc')//->field("hobby,remark,tag")
				  ->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);
		$this->assign("list",$list);
		$this->assign("keys",$keys);
		
		$this->display();	
	}
	
	/**
	 * 会员详情
	 */
	public function detail(){
		
		$id     = $this->_param("id");
		$member = D("MemberInfoView");
		$member = $member->find($id);
		$this->assign("member",$member);
		
		$this->display();
	}

	
	/**
	 * 修改会员资料
	 */
	public function member_edit(){
		
		$userid = session(C('USER_AUTH_KEY'));
		$model  = M("User");
		$data   = $model->find($userid);
		
		if(IS_POST){
			$model->create();
			$model->id = $userid;
			$solevar   = $model->solevar; 
			$password  = $this->_post("epassword");
			if($password != C("CONFUSE")){
				$model->password = myencrypt($password);
			}
			$model->save();
			
			$this->assign("jumpUrl",U('Index/index'));
			$this->success("修改个人资料成功");
		}else{
			$this->assign("detail",$data);
			$this->display();
		}
	}
	
	/**
	 * 用户数据分享统计
	 */
	public function share_user(){
	
		$id    = $this->_param("id","trim",0);
		$model = M("Member");
		$rows  = $model->find($id);
		$this->assign("user",$rows);
	
		$num  = $this->_param("num","intval",7);
		$maps['num']    = $num;
		$maps['userid'] = $rows['userid'];
		$maps['type']   = "day";
	
		$json  = sendRest("Total/behavior_index",$maps);
	
		$this->assign("detail",$json['data']);
		$this->assign("today", date("m-d"));
		$this->assign("yesday",date("m-d",time()-86400));
	
		$this->display();
	}
	
	/**
	 * 用户行为记录列表
	 */
	public function member_behavior(){
		
		$id    = $this->_param("id","intval",0);
	
		$model = D("Total");
		$list  = $model->memberBehavior($id);
		$this->assign("list",$list);
	
		$this->display();
	}
	
	
	/**
	 * 用户导引用户列表
	 */
	public function member_import(){
	
		$id    = $this->_param("id","intval",0);
	
		$model = D("Total");
		$list  = $model->memberImport($id);
		$this->assign("list",$list);
	
		$this->display();
	}
}
?>